package com.web.kongjian.web;



import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.servlet.ModelAndView;

import com.base.kongjian.entity.RealInform;
import com.base.user.entity.Member;
import com.web.kongjian.ao.KongjianAo;
import com.web.kongjian.ao.utils.KongjianUtils;

@Controller
@RequestMapping("/kj")
public class KongjianAction
{
	@Autowired
	private KongjianAo kongjianAo;
	
	@RequestMapping ("/deleteCollection")
	public ModelAndView deleteCollection(HttpServletRequest request,HttpServletResponse response,String type,long workId)
	{
		kongjianAo.deleteWorks (request ,type,workId);
		
		return null;
	}
	
	@RequestMapping("/deleteVisitor")
	public ModelAndView deleteVisitor(HttpServletRequest request,long visitor_MId)
	{
		kongjianAo.deleteVisitor (request ,visitor_MId);
		
		return null;
	}
	
	@RequestMapping("/intoBlackFriend")
	public ModelAndView intoBlackFriend(HttpServletRequest request,long visitor_MId)
	{
		kongjianAo.intoBlackFriend (request ,visitor_MId);
		
		return null;
	}
	
	@RequestMapping ("/deleteFriend")
	public ModelAndView deleteFriend(HttpServletRequest request,long friend_id)
	{
		kongjianAo.deleteFriend (request ,friend_id);
		return null;
	}
	
	@RequestMapping ("/blackList")
	public ModelAndView blackList(HttpServletRequest request,long friend_id)
	{
		kongjianAo.blackList (request ,friend_id);
		return null;
	}
	
	@RequestMapping ("/edit")
	public ModelAndView edit(HttpServletRequest request,Member m,HttpServletResponse response) throws IOException
	{
		kongjianAo.edit (request ,m);
		long memberId = KongjianUtils.getMemberIdByCookie (request);
		String url = "/u/"+memberId+"?conPage=op_success&callback=?conPage=userInfor";
		response.sendRedirect (url);
		
		return null;
	}
	@RequestMapping("/headerEdit")
	public ModelAndView headerEdit(HttpServletRequest request,HttpServletResponse response,MultipartFile photoFile ,MultipartHttpServletRequest mtRequest) throws IOException
	{
		photoFile = mtRequest.getFiles ("photoFile").get(0);
		kongjianAo.headerEdit (mtRequest ,photoFile);
		long memberId = KongjianUtils.getMemberIdByCookie (request);
		String url = "/u/"+memberId+"?conPage=op_success&callback=?conPage=headerSet";
		response.sendRedirect (url);
		
		return null;
	}
	
	@RequestMapping("/signEidt")
	public ModelAndView signEidt(HttpServletRequest request,String content,HttpServletResponse response) throws IOException
	{
		kongjianAo.signEidt (request,content);
		long memberId = KongjianUtils.getMemberIdByCookie (request);
		String url = "/u/"+memberId+"?conPage=op_success&callback=?conPage=sign";
		response.sendRedirect (url);
		
		return null;
	}
	
	@RequestMapping("/realInformEdit")
	public ModelAndView realInformEdit(HttpServletRequest request,HttpServletResponse response,RealInform r) throws IOException
	{
		kongjianAo.realInformEdit (request ,r);
		long memberId = KongjianUtils.getMemberIdByCookie (request);
		String url = "/u/"+memberId+"?conPage=op_success&callback=?conPage=realInfor";
		response.sendRedirect (url);
		
		return null;
	}

	@RequestMapping("/passValidate")
	public ModelAndView passValidate(HttpServletRequest request,String old,HttpServletResponse response) throws IOException
	{
		String string = kongjianAo.passValidate (request ,old);
		response.setContentType("text/html;charset=gb2312");
		PrintWriter out = response.getWriter();

		out.print(string);
		out.flush();
		out.close();
		
		return null;
	}
	
	@RequestMapping("/passwordEdit")
	public ModelAndView passwordEdit(HttpServletRequest request,String new_password,HttpServletResponse response) throws IOException
	{
		kongjianAo.passwordEdit (request ,new_password);
		long memberId = KongjianUtils.getMemberIdByCookie (request);
		String url = "/u/"+memberId+"?conPage=op_success&callback=?conPage=re_password";
		response.sendRedirect (url);
		
		return null;
	}
	
	@RequestMapping("/addFriendFromBlack")
	public ModelAndView addFriendFromBlack(HttpServletRequest request,long friend_id)
	{
		
		kongjianAo.addFriendFromBlack (request ,friend_id);
		
		
		return null;
	}
	
	@RequestMapping("/deleteBlackFriend")
	public ModelAndView deleteBlackFriend(HttpServletRequest request,long friend_id)
	{
		kongjianAo.deleteBlackFriend (request ,friend_id);
		
		return null;
	}
}
